package com.peko.es.es.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * @author Peko
 */

@Data
/**
 * 作用在类上，将对象映射成ES中一条json格式文档
 * 注意：ES服务器中之前不能存在此索引名，在往索引里添加文档时，才会创建该索引
 */
@Document(indexName = "ems")
public class Emp {
    @Id
    private String id;
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String name;
    @Field(type = FieldType.Integer)
    private Integer age;
    //试了好几个时间格式，就这个靠谱
    //@Field(type = FieldType.Date,format = DateFormat.basic_date_time)
    @Field(type = FieldType.Date,format = DateFormat.custom,pattern = "yyyy-MM-dd HH:mm:ss")
//    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-DD HH:mm:ss",timezone = "GMT+8")
    private Date bir;
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String context;
}
